/*
 * This file is part of LexiToolsMobile
 *  
 * Author: Jerzy Wawro
 * ver. 1.00
 * Copyright: Tenar (http://www.tenar.pl)
 *
 * Mobile LexiTools is an open source project; you can redistribute it 
 * and/or modify it under the terms of the license as published -  GPL with 
 * the following modification:  fragments of the code may be not copyleft 
 * (hidden), to protect contents of the dicionaries.
 * In this case the author of non-public fragments of the code is obliged 
 * to make available functionally equivalent code for unprotected dictionaries.
 * 
 * Mobile LexiTools is distributed WITHOUT ANY WARRANTY.
 * See the license for more details.
 *  
 * You should have received a copy of the GNU General Public License
 * along with LexiToolsMobile (see: gpl.txt); if not - you can find it 
 * on web page http://www.fsf.org/, or write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package dict;

import java.util.*;
import java.io.*;
import javax.microedition.io.*;
//#if FileConnection=="1"
//# import javax.microedition.io.file.*;
//#endif
import com.Callback;

import javax.microedition.lcdui.*;

public final class warp{
    std_dict[] dct = new std_dict[10];
    int iMAX_DICT = 10;
    int iDictCount = 0;
    int iDefaultDict = 0;
    Callback cbk;
    
    /** Constructor. */
    public warp() {
//!! odszukanie s�ownik�w na r�znych mediach        FindDicts();  
    }


    
  void do_search() {
//#if FileConnection=="1"     
//#     FileConnection fc;
//#     FileConnection fcr;
//#     Enumeration filelist;
//#     InputStream iniFile;
//#     String HomeDir;
//#     String root;
//#     String fileName;
//#     byte[] buff = new byte[512];
//#     int iSize = 0;
//#     String DictDef;
//#     Enumeration drives;
//# 
//#     drives = FileSystemRegistry.listRoots();
//#     while ( drives.hasMoreElements() )  {
//#             try {
//#                 root = (String) drives.nextElement();
//#                 HomeDir = "file:///" + root /*+"Data/"*/;
//#                 fcr=(FileConnection)Connector.open(HomeDir);
//#                 filelist = fcr.list("*.dlt", true);
//#                 while(filelist.hasMoreElements()) {
//#                   fileName = (String) filelist.nextElement();
//#                   try {
//#                     fc = (FileConnection)Connector.open(HomeDir + fileName);
//#                     if (fc.exists()) {
//#                         iniFile = fc.openInputStream();
//#                         iSize=iniFile.read(buff);
//#                         iniFile.close();
//#                         if ( iSize>0 ) {
//#                            DictDef=new String(buff,0, iSize); 
//#                            dct[iDictCount] = new std_dict(
//#                                    HomeDir+DictDef, DictDef, "pl", 
//#                                    (short)261, "en", (short)262);
//#                            iDictCount++;
//#                         }
//#                     }
//#                     fc.close();
//#                   }
//#                     catch (Exception e) {
//#                   }
//#                 }
//#                 fcr.close();
//#             } catch (IOException ioe) {
//#                 System.out.println(ioe.getMessage());
//#             }
//#     }
//#     cbk.cb_completed(1, String.valueOf(iDictCount));
//#endif    
  }
    
public void OpenDictionaries(){
  dct[0] = new std_dict("/", "tas", "pl", (short)2464, "en", (short)2660);
//  dct[0] = new std_dict("/", "min", "pl", (short)255, "en", (short)258);    
  iDictCount = 0;
}

public String FindFirst(int l, boolean eq, boolean exactly, String key) {
    if (l==0) return dct[iDefaultDict].FindFirst_l0(key,eq,exactly);
    else  return dct[iDefaultDict].FindFirst_l1(key,eq,exactly);
}

public String FindNext(int l, boolean eq) {
    if (l==0) return dct[iDefaultDict].FindNext_l0(eq);
    else  return dct[iDefaultDict].FindNext_l1(eq);
}


public void FindDicts(Callback callback) {

    cbk=callback;
    new Thread(new Runnable() {
        public void run() {
            do_search();
        }
        }).start();
 }

}
